define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'methods/index/index' + location.search,
                    add_url: 'methods/index/add',
                    edit_url: 'methods/index/edit',
                    del_url: 'methods/index/del',
                    multi_url: 'methods/index/multi',
                    table: 'ip_methods',
                }
            });

            var table = $("#table");
//给添加按钮添加`data-area`属性
            $(".btn-add").data("area", ["100%", "100%"]);
//当内容渲染完成给编辑按钮添加`data-area`属性
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone").data("area", ["100%", "100%"]);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle: false,
                showColumns: false,
                visible: false,
                showExport: false,
                commonSearch: false,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title')},
                        // {field: 'score', title: __('Score')},
                        {field: 'days', title: __('Days')},
                        // {field: 'trueness_con', title: __('Trueness_con'), searchList: {"":__(''),"<":__('<'),"<=":__('<='),"=":__('='),">=":__('>='),">":__('>')}, formatter: Table.api.formatter.normal},
                        {field: 'trueness', title: __('Trueness'),formatter: Controller.api.formatter.true_ness},
                        {field: 'type_id', title: __('Type_id')},
                        // {field: 'provice_include', title: __('Provice_include'), searchList: {"":__(''),"包含":__('包含'),"不包含":__('不包含')}, formatter: Table.api.formatter.normal},
                        {field: 'provice', title: __('Provice'),formatter: Controller.api.formatter.is_provice},
                        // {field: 'city_include', title: __('City_include'), searchList: {"":__(''),"包含":__('包含'),"不包含":__('不包含')}, formatter: Table.api.formatter.normal},
                        {field: 'city', title: __('City'),formatter: Controller.api.formatter.is_city},
                        // {field: 'visit_con', title: __('Visit_con'), searchList: {"IP访问次数>":__('Ip访问次数>'),"IP段访问总次数>":__('Ip段访问总次数>'),"IP段访问IP个数>":__('Ip段访问ip个数>')}, formatter: Table.api.formatter.normal},
                        {field: 'carrier', title: __('Carrier'), searchList: {"移动":__('移动'),"联通":__('联通'),"电信":__('电信'),"其他":__('其他')}, formatter: Table.api.formatter.normal},
                        // {field: 'begintime', title: __('Begintime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'visit', title: __('Visit'),formatter: Controller.api.formatter.is_visit},
                        {field: 'score', title: __('Score')},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                true_ness:function(value, row, index){
                    if (!row.trueness_con || !row.trueness){
                        return '';
                    }
                    return row.trueness_con + '&nbsp;' +row.trueness;
                },
                is_provice:function(value, row, index){
                    if (!row.provice_include || !row.provice){
                        return '';
                    }
                    return row.provice_include + '&nbsp;' +row.provice;
                },
                is_city:function(value, row, index){
                    if (!row.city_include || !row.city){
                        return '';
                    }
                    return row.city_include + '&nbsp;' +row.city;
                },
                is_visit:function(value, row, index){
                    if (!row.visit_con || !row.visit){
                        return '';
                    }
                    return row.visit_con + '&nbsp;' +row.visit;
                },
            }
        }
    };
    return Controller;
});